<template>
  <div class="bg">
    <img src="../assets/img/login_bg.png" />
    <div class="cont">
      <h1>
        教得慧-智慧大脑
        <br />管理中心
      </h1>
      <el-form ref="form" :model="form">
        <el-form-item>
          <el-input v-model="form.userName"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="form.password" type="password"></el-input>
        </el-form-item>
        <el-form-item style="text-align:center">
          <el-button style="width:200px" type="primary" @click="onSubmit">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<style>
.bg .el-form {
  width: 350px;
  margin: 26px auto 0 auto;
}

.bg .cont {
  height: 290px;
  width: 550px;
  position: absolute;
  top: 50%;
  margin-top: -145px;
  left: 50%;
  margin-left: -275px;
}

.bg input {
  height: 50px !important;
  background: #fff;
  border-radius: 40px !important;
  font-size: 14px !important;
  color: #111 !important;
  padding: 0 30px !important;
}

.bg button {
  width: 350px;
  height: 50px;
  background: #55e4c2 !important;
  border-radius: 40px !important;
  border: 0 !important;
}

.bg span {
  font-size: 24px;
  font-weight: 800;
  color: #ffffff;
}
</style>
<script>
export default {
  name: 'login',
  data() {
    return {
      form: {
        userName: '',
        password: '',
      },
    }
  },
  created() {
    sessionStorage.removeItem('token')
    sessionStorage.removeItem('school_name')
    localStorage.removeItem('nickname')
  },
  methods: {
    onSubmit() {
      const that = this
      this.axios({
        method: 'post',
        data: {
          account: this.form.userName,
          password: this.form.password,
        },
        url: this.$api + '/index/user/login',
      }).then(function (res) {
        if (res.data.code === 1) {
          sessionStorage.setItem('token', res.data.data.token)
          sessionStorage.setItem('school_name', res.data.data.school_name)
          localStorage.setItem('nickname', res.data.data.nickname)
          that.$message({
            message: '登录成功！',
            type: 'success',
          })
          that.$router.push({
            name: 'index',
          })
        } else {
          that.$message.error(res.data.msg)
        }
      })
    },
  },
}
</script>
